<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Jedrzej\Pimpable\PimpableTrait;

class StoreOrderInvoice extends Model
{
    use HasFactory;
    use PimpableTrait;
    use SoftDeletes;

    /**
     *可批量赋值的字段
     */
    public $fillable = [
        'user_id',
        'order_id',
        'invoice_id',
        'category',
        'header_type',
        'type',
        'name',
        'duty_number',
        'drawer_phone',
        'email',
        'tell',
        'address',
        'bank',
        'card_number',
        'invoice_number',
        'remark',
        'invoice_time',
    ];


    /**
     * 可搜索的字段
     */
    public $searchable = [
        'user_id',
        'order_id',
        'name',
        'duty_number',
        'drawer_phone',
        'email',
        'tell',
        'address',
        'bank',
        'card_number',
        'invoice_number',
    ];



    /**
     * 默认倒序排序
     */
    protected $defaultSortCriteria = ['id,desc'];


    /**
     *发票表所关联的用户
     */
    public function user(){
        return $this->hasMany(User::class,'user_id','id');
    }

    /**
     * 发票表所关联的订单
     */
    public function orders(){
        return $this->belongsTo(Order::class,'order_id','id');
    }



}
